<template>
  <view class="sleep-selector">
    <view class="sleep-title">睡眠质量</view>
    <view class="sleep-options">
      <view 
        v-for="(option, index) in sleepOptions" 
        :key="index"
        class="sleep-item"
        :class="{ active: selectedQuality === option.value }"
        @click="selectQuality(option.value)"
      >
        <text class="sleep-emoji">{{ option.emoji }}</text>
        <text class="sleep-label">{{ option.label }}</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'SleepSelector',
  data() {
    return {
      selectedQuality: '',
      sleepOptions: [
        { value: 'good', emoji: '😴', label: '很好' },
        { value: 'normal', emoji: '🛌', label: '一般' },
        { value: 'bad', emoji: '😫', label: '很差' }
      ]
    }
  },
  methods: {
    selectQuality(quality) {
      this.selectedQuality = quality
      this.$emit('select', quality)
    },
    reset() {
      this.selectedQuality = ''
    }
  }
}
</script>

<style scoped>
.sleep-selector {
  background-color: #fff;
  border-radius: 16rpx;
  padding: 30rpx;
  margin-bottom: 20rpx;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
}

.sleep-title {
  font-size: 32rpx;
  color: #333;
  margin-bottom: 30rpx;
  font-weight: bold;
  text-align: center;
  position: relative;
}

.sleep-title::after {
  content: '';
  position: absolute;
  bottom: -10rpx;
  left: 50%;
  transform: translateX(-50%);
  width: 60rpx;
  height: 4rpx;
  background-color: #e8f5e9;
  border-radius: 2rpx;
}

.sleep-options {
  display: flex;
  justify-content: space-around;
  margin-top: 20rpx;
}

.sleep-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 30%;
  padding: 20rpx 0;
  border-radius: 12rpx;
  transition: all 0.3s;
  border: 2rpx solid transparent;
}

.sleep-item.active {
  background-color: #e8f5e9;
  box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.1);
  border: 2rpx solid #c8e6c9;
  transform: scale(1.05);
}

.sleep-emoji {
  font-size: 56rpx;
  margin-bottom: 12rpx;
}

.sleep-label {
  font-size: 24rpx;
  color: #666;
  font-weight: 500;
}
</style>